#include<iostream>
#include<string>
using namespace std;
struct customer
{
    string name;
    int time;
    int arrive;
    int wait;
    int quan;
};
typedef struct customer* Customer;
struct que
{
    struct customer* name;
    int front, rear;
    int MAXSIZE;
};
typedef struct que* Queue;
Queue CreateQueue(int n)
{
    Queue Q = new struct que;
    Q->front = Q->rear = -1;
    Q->MAXSIZE = n;
    Q->name = new struct customer[Q->MAXSIZE];
    return Q;
}
void enqueue(Queue Q, struct customer X)
{
    Q->name[++Q->rear] = X;
}
struct customer dequeue(Queue Q)
{
    return Q->name[++Q->front];
}
struct customer top(Queue Q)
{
    return Q->name[Q->front + 1];
}
int main()
{
    int N, M;
    cin >> N >> M;
    Queue Q = CreateQueue(N);
    int i, j, k;
    int d, t1, t2;
    string s;
    Customer sr = new struct customer[N];
    Customer p = new struct customer[N];
    for (i = 0; i < N; i++)
    {
        p[i].quan = -1;
        p[i].wait = -1;
    }
    if (M > 0)
    {
        k = 0;
        for (i = 0; i < M; i++)
        {
            cin >> d;
            for (j = 0; j < d; j++)
            {
                cin >> s;
                sr[k].name = s;
                sr[k].quan = i;
                k++;
            }
        }
        for (i = 0; i < N; i++)
        {
            cin >> s;
            cin >> t1;
            cin >> t2;
            p[i].name = s;
            p[i].arrive = t1;
            if (t2 <= 60) p[i].time = t2;
            else p[i].time = 60;
        }
        for (i = 0; i < k; i++)
        {
            j = 0;
            while (sr[i].name != p[j].name)
            {
                j++;
            }
            p[j].quan = sr[i].quan;
        }
        int time = 0; int ta;
        i = 0;
        enqueue(Q, p[i]);
        p[i].wait = 0;
        ta = p[i].arrive;
        i++;
        while (p[i].arrive == 0)
        {
            enqueue(Q, p[i]);
            p[i].wait = 0;
            i++;
        }
        while (Q->front != Q->rear)
        {
            if (top(Q).wait == -1)cout << top(Q).name << endl;
            if (top(Q).wait == -1)
            {
                Q->name[Q->front + 1].wait = ta - Q->name[Q->front + 1].arrive;
                Q->name[Q->front + 1].time += ta;
                ta = Q->name[Q->front + 1].time;
                for (j = Q->front + 2; j <= Q->rear; j++)
                {
                    if (Q->name[j].quan == top(Q).quan)
                    {
                        Q->name[j].wait = ta - Q->name[j].arrive;
                        Q->name[Q->front + 1].time += Q->name[j].time;
                        ta = Q->name[Q->front + 1].time;
                        cout << Q->name[j].name << endl;
                    }
                }
                for (i = 0; i < N; i++)
                {
                    if (p[i].arrive <= top(Q).time && p[i].wait == -1)
                    {
                        if (p[i].quan == top(Q).quan)
                        {
                            p[i].wait = ta - p[i].arrive;
                            Q->name[Q->front + 1].time += p[i].time;
                            ta = Q->name[Q->front + 1].time;
                            cout << p[i].name << endl;
                        }
                        enqueue(Q, p[i]);
                        p[i].wait = 0;
                    }
                }
            }
            time = time + dequeue(Q).wait;
            if (Q->front == Q->rear)
            {
                int flag = 0;
                for (i = 0; i < N; i++)
                {
                    if (p[i].wait != 0)
                    {
                        flag = 1;
                        break;
                    }
                }
                if (flag)
                {
                    enqueue(Q, p[i]);
                    p[i].wait = 0;
                    ta = p[i].arrive;
                }
            }
        }
        printf("%.1f", 1.0 * time / N);
    }
    else
    {
        for (i = 0; i < N; i++)
        {
            cin >> s;
            cin >> t1;
            cin >> t2;
            p[i].name = s;
            p[i].arrive = t1;
            if (t2 <= 60) p[i].time = t2;
            else p[i].time = 60;
        }
        int time = 0, timep = 0;
        for (i = 0; i < N; i++)
        {
            cout << p[i].name << endl;
            if (i > 0)
            {
                timep += p[i - 1].time;
                time = time + timep - p[i].arrive;
            }
        }
        printf("%.1f", 1.0 * time / N);
    }
    return 0;
}
